﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Marbles.Core.Authentication;
using Marbles.Core.Content.Sites;

namespace Marbles.Core.Handlers
{
    public abstract class HttpHandlerBase
    {

        public IToken CurrentToken
        {
            get
            {
                if (this.AuthenticationProvider == null) { return null; }
                return this.AuthenticationProvider.CurrentToken;
            }
        }

        public Marbles.Core.Authentication.AuthenticationProvider AuthenticationProvider
        {
            get { return Marbles.Core.Authentication.AuthenticationProvider.CreateProviderInstance(); }
        }

        public bool IsEditor
        {
            get
            {
                IToken token = this.AuthenticationProvider.CurrentToken;
                return (token == null) ? false : token.IsEditor;
            }
        }

        public string Username
        {
            get
            {
                IToken token = this.AuthenticationProvider.CurrentToken;
                return (token == null) ? "" : token.Username;
            }
        }

        public bool IsAdministrator
        {
            get
            {
                IToken token = this.AuthenticationProvider.CurrentToken;
                return (token == null) ? false : token.IsAdministrator;
            }
        }

        public bool isViewer
        {
            get
            {
                IToken token = this.AuthenticationProvider.CurrentToken;
                return (token == null) ? true : token.IsViewer;
            }
        }

        public SiteDefinition Web
        {
            get { return SiteDefinition.GetCurrent(); }
        }
    }
}
